package com.wangkm.roomdemo

import android.arch.persistence.db.SupportSQLiteDatabase
import android.arch.persistence.room.Database
import android.arch.persistence.room.RoomDatabase
import android.arch.persistence.room.migration.Migration

/**
 * @author: created by wangkm
 * @Time: 2020/9/15 11:47
 * @Des： $
 * @Email: 1240413544@qq.com
 */
@Database(entities = [User::class], version = 2)
abstract class AppDatabase : RoomDatabase() {
    abstract fun userDao(): UserDao?

    companion object {
        //数据库变动添加Migration
        val MIGRATION_1_2: Migration = object : Migration(1, 2) {
            override fun migrate(database: SupportSQLiteDatabase) {
                database.execSQL("ALTER TABLE user "
                        + " ADD COLUMN age INTEGER NOT NULL DEFAULT 0")
            }
        }
    }
}